package com.qing.gui.jframe;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 弹窗
 */
public class Dialog extends JFrame {

    public void init(){
        JFrame jFrame = new JFrame("实现弹窗");
        jFrame.setVisible(true);
        jFrame.setBounds(100,100,600,600);
        jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        //获得容器
        Container contentPane = jFrame.getContentPane();
        //使用绝对定位布局
        contentPane.setLayout(null);

        contentPane.setBackground(Color.PINK);

        JButton button = new JButton("点我弹窗！");
        button.setBounds(20,20,200,50);
        contentPane.add(button);
        //设置按钮的监听事件
        button.addActionListener(e -> {new MyDialog();});
    }


    public static void main(String[] args) {
        new Dialog().init();
    }
}
